package com.xinlu.user.dao;

import java.util.List;

import com.xinlu.derek.common.BaseDao;
import com.xinlu.persistence.Users;
import com.xinlu.persistence.Yhxx;
import com.xinlu.util.tool.PageObject;

public class YhxxDao extends BaseDao {

	/**
	 * 获取未读消息数
	 * 
	 * @param user
	 * @return
	 */
	public int getWeiDuXiaoXi(Users user) {

		String cmdText = "from Yhxx where state=0 and username='" + user.getUsername() + "'";
		List lst = super.find(cmdText);
		if (lst == null) {
			return 0;
		} else {
			return lst.size();
		}
	}

	/**
	 * 保存
	 * 
	 * @param yhxx
	 */
	public void save(Yhxx yhxx) {
		super.save(yhxx);
	}

	/**
	 * 加载
	 * 
	 * @param id
	 * @return
	 */
	public Yhxx load(java.lang.Integer id) {
		return (Yhxx) super.load(Yhxx.class, id);
	}

	/**
	 * 更新
	 * 
	 * @param yhxx
	 */
	public void update(Yhxx yhxx) {
		super.update(yhxx);
	}

	/**
	 * 加载用户消息
	 * 
	 * @param username
	 * @param state
	 * @param pageNo
	 * @return
	 */
	public PageObject loadYhxx(String username, String state, int pageNo) {
		String cmdText = "select * from YHXX where username='" + username + "' ";
		if (!"--全部--".equals(state)) {
			cmdText += " and state=" + state;
		}

		return super.findPageObjectByProc(10, pageNo, cmdText, Yhxx.class);
	}

	/**
	 * 获取未读消息数
	 * 
	 * @param user
	 * @param cktx
	 * @param qktx
	 * @param pjtx
	 * @param fdtx
	 * @return
	 */
	public int getWeiDuXiaoXi(Users user, int cktx, int qktx, int pjtx, int fdtx) {
		
		String cmdText = "from Yhxx where state=0 and username='" + user.getUsername() + "' ";
		if (cktx == 0) {
			cmdText += " and msgtype<>'存款'";
		}
		if (qktx == 0) {
			cmdText += " and msgtype<>'取款'";
		}
		if (pjtx == 0) {
			cmdText += " and msgtype<>'派奖'";
		}
		if (fdtx == 0) {
			cmdText += " and msgtype<>'返点'";
		}
		
		List lst = super.find(cmdText);
		if (lst == null) {
			return 0;
		} else {
			return lst.size();
		}
	}
}
